<?php
class M_productpic extends CI_Model {
    function __construct() {
        parent::__construct();
    }

    function get_count($data) {
        $this->db->from('productpic');
        $this->db->select('count(1) as cnt');
        $this->db->where($data);
        $result = $this->db->get()->row_array();
        return $result['cnt'];
    }

    function get_productpic($data) {
        if (isset($data['column'])) {
            $this->db->select($data['column']);
        }
        $this->db->from('productpic');
        if (!isset($data['productpicid'])) {
            return false;
        }
        $this->db->where('productpicid', $data['productpicid']);
        return $this->db->get()->row_array();
    }

    function get_productpic_list($data) {
        $this->db->from('productpic');
        if (isset($data['limit'])) {
            $this->db->limit($data['limit'], $data['offset']);
        }
        if (isset($data['where'])) {
            if(isset($data['where']['title'])){
                $this->db->like('title',$data['where']['title']);
                unset($data['where']['title']);
            }
            $this->db->where($data['where']);
        }
        if (isset($data['order'])) {
            $this->db->order_by($data['order']);
        }
        if (isset($data['column'])) {
            $this->db->select($data['column']);
        }
        $query = $this->db->get();
        return $query->result_array();
    }

    function insert($data) {
        $this->db->insert('productpic', $data);
    }

    function update($data) {
        if (!isset($data['productpicid'])) {
            return false;
        }
        $this->db->where('productpicid', $data['productpicid']);
        unset($data['productpicid']);
        return $this->db->update('productpic', $data);
    }

    function delete($data) {
        return $this->db->delete('productpic', $data);
    }

}
